//
//  MMEraserViewController.m
//  MemeMaker
//
//  Created by Phan Quang Ha on 7/31/13.
//  Copyright (c) 2013 soyo. All rights reserved.
//

#import "MMEraserViewController.h"
#import "MMCircleView.h"

@interface MMEraserViewController ()

@end

@implementation MMEraserViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.circleView.isPreviewing = YES;
    
    GADBannerView *adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    adBanner.rootViewController = self;
    adBanner.adUnitID = ADMOB_PUBLISHER_ID;
    [self.viewAd addSubview:adBanner];
    [adBanner loadRequest:[GADRequest request]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setSliderSize:nil];
    [self setBtnConfirm:nil];
    [self setBtnCancel:nil];
    [self setCircleView:nil];
    [super viewDidUnload];
}
- (IBAction)confirm:(UIButton *)sender {
    
    if (_delegate && [_delegate respondsToSelector:@selector(didSelectSize:)]) {
        [_delegate didSelectSize:_sliderSize.value];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)cancel:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)didChangeSize:(UISlider *)sender {
    CGPoint center = self.circleView.center;
    self.circleView.frame = CGRectMake(0, 0, sender.value, sender.value);
    self.circleView.center = center;
}
#pragma mark - Ad Delegate
//- (void)adViewDidReceiveAd:(GADBannerView *)view
//{
//    [UIView animateWithDuration:0.2 animations:^{
//        CGRect tableRect = self.tblItems.frame;
//        CGRect bannerRect = self.viewAd.frame;
//        
//        tableRect.size.height = self.view.frame.size.height - bannerRect.size.height;
//        bannerRect.origin.y = tableRect.size.height;
//        
//        self.tblItems.frame = tableRect;
//        self.viewAd.frame = bannerRect;
//    }];
//}
//- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
//{
//    NSLog(@"Ad Error:%@",error);
//    [UIView animateWithDuration:0.2 animations:^{
//        CGRect tableRect = self.tblItems.frame;
//        CGRect bannerRect = self.viewAd.frame;
//        
//        tableRect.size.height = self.view.frame.size.height;
//        bannerRect.origin.y = tableRect.size.height;
//        
//        self.tblItems.frame = tableRect;
//        self.viewAd.frame = bannerRect;
//    }];
//}

@end
